//
//  EFSJump.m
//  EFSMobile
//
//  Created by Chuan on 11/19/15.
//  Copyright © 2015 Elephants Financial Service. All rights reserved.
//

#import "EFSJump.h"

@implementation EFSJump

NSString * __attribute__((annotate("oclint:suppress[long method]"),annotate("oclint:suppress[high ncss method]")))
jumpTypeMap(JumpType type)
{
    NSString *typeStr;
    switch (type) {
        case JumpTypeNone:
            break;
        case JumpTypeSecretary:
            typeStr = @"Secretary";
            break;
        case JumpTypeActivity:
            typeStr = @"activity";
            break;
        case JumpTypeArticle:
            typeStr = @"article";
            break;
        case JumpTypeLotto:
        case JumpTypeExpertArticle:
        case JumpTypeExpertInfo:
        case JumpTypeTradePlan:
        case JumpTypeFinancialCalendar:
            break;
        case JumpTypeOpenAccount:
            typeStr = @"OpenAccount";
            break;
        case JumpTypeImage:
            typeStr = @"image";
            break;
        case JumpTypeQuote:
            typeStr = @"ChartDetail";
            break;
        case JumpTypeLogin:
            typeStr = @"login";
            break;
        case JumpTypeBindPhone:
            typeStr = @"bindPhone";
            break;
        case JumpTypeStrategy:
            typeStr = @"strategy";
            break;
        case JumpTypeMarketTips:
            typeStr = @"marketTips";
            break;
        case JumpTypeNFXGTradeHoldingPositions:
            typeStr = @"NFXGTradeHoldingPositions";
            break;
        case JumpTypeNFXGTradeStopOrder:
            typeStr = @"NFXGTradeStopOrder";
            break;
        case JumpTypeEFSTradBuySell:
            typeStr = @"NFXGPageView";
            break;
        case JumpTypeEFSTradBuy:
            typeStr = @"NFXGTradeBuy";
            break;
        case JumpTypeEFSTradSell:
            typeStr = @"NFXGTradeSell";
            break;
        case JumpTypeNFXGTradeConditionalOrder:
            typeStr = @"NFXGTradeConditionalOrder";
            break;
        case JumpTypeNFXGTradeOrderForm:
            typeStr = @"NFXGTradeOrderForm";
            break;
        case JumpTypeNFXGTradeFilledOrderForm:
            typeStr = @"NFXGTradeFilledOrderForm";
            break;
        case JumpTypeNFXGTradeTransfer:
            typeStr = @"NFXGTradeTransfer";
            break;
        case JumpTypeNFXGTradePay:
            typeStr = @"NFXGPay";
            break;
        case JumpTypeNFXGTradePayPageView:
            typeStr = @"NFXGPageView";
            break;
        case JumpTypeTabHome:
            typeStr = @"TabHome";
            break;
        case JumpTypeYGTrade:
            typeStr = @"YGTrade";
            break;
        case JumpTypeTradeLoginSelect:
            typeStr = @"TradeLoginSelect";
            break;
            
        case JumpTypeSecretaryToBindPhone:
            typeStr = @"FromSecretaryToBindPhone";
            break;
            
        default:
            break;
    }
    return typeStr;
}

+ (void)jump:(JumpType)jumpType withData:(id)data from:(UIViewController *)sender;
{
    SEL s = NSSelectorFromString([NSString stringWithFormat:@"jump%@:", jumpTypeMap(jumpType)]);
    if ([EFSJumpManager respondsToSelector:s]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        if ([sender respondsToSelector:NSSelectorFromString(@"viewWillGoto")]) {
            [sender performSelector:NSSelectorFromString(@"viewWillGoto")];
        }
        [EFSJumpManager performSelector:s withObject:@[data ?: @{}, sender] afterDelay:0];
        if ([sender respondsToSelector:NSSelectorFromString(@"viewDidGoto")]) {
            [sender performSelector:NSSelectorFromString(@"viewDidGoto")];
        }
#pragma clang diagnostic pop
    } else {
        NSLog(@"undefined JumpType: [%@]", jumpTypeMap(jumpType));
    }
}

@end
